#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QToolBar>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 创建菜单栏
    QMenuBar* menuBar = this->menuBar();
    this->setMenuBar(menuBar);

    // 创建菜单
    QMenu* menu = new QMenu("菜单");
    menuBar->addMenu(menu);

    // 创建工具栏
    QToolBar* toolBar = new QToolBar();
    QToolBar* toolBar2 = new QToolBar();
    this->addToolBar(toolBar);
    this->addToolBar(Qt::RightToolBarArea, toolBar2);

    // 设置停靠、浮动、移动
    toolBar2->setAllowedAreas(Qt::LeftToolBarArea | Qt::RightToolBarArea);
    toolBar2->setFloatable(false);
    toolBar2->setMovable(true);

    // 创建菜单项
    QAction* action1 = new QAction("菜单项1");
    QAction* action2 = new QAction("菜单项2");
    // 将菜单项加载到菜单中
    menu->addAction(action1);
    menu->addAction(action2);

    connect(action1, &QAction::triggered, this, &MainWindow::handle1);
    connect(action2, &QAction::triggered, this, &MainWindow::handle2);

    // 创建工具项
    QAction* action3 = new QAction("工具1");
    QAction* action4 = new QAction("工具2");
    QAction* action5 = new QAction("工具3");
    QAction* action6 = new QAction("工具4");
    // 添加工具项
    toolBar->addAction(action3);
    toolBar->addAction(action4);
    toolBar2->addAction(action5);
    toolBar2->addAction(action6);

}

void MainWindow::handle1()
{
    qDebug() << "handle1";
}

void MainWindow::handle2()
{
    qDebug() << "handle2";
}

MainWindow::~MainWindow()
{
    delete ui;
}

